export default {
    updateLocalStorage(state) {
        window.localStorage.setItem('lognUser', JSON.stringify(state.lognUser));
    },
    changeLogn(state, data) {
        state.lognUser = data;
        // window.localStorage.setItem('lognUser', JSON.stringify(data));
        // this.commit('updateLocalStorage')
        //     state.lognUser = {
        //     ...data
        // }
    },
    signout(state) {
        state.lognUser = null;
        window.localStorage.removeItem('lognUser');
    },
    addAddress(state, data) {
        state.lognUser.address.push(data);
        // window.localStorage.setItem('lognUser', JSON.stringify(state.lognUser));
        this.commit('updateLocalStorage')
    },
    changeAddress(state, payload) {
        state.lognUser.address.splice(payload.index, 1, payload.data);
        // window.localStorage.setItem('lognUser', JSON.stringify(state.lognUser));
        this.commit('updateLocalStorage')
    },
    deleAddress(state, payload) {
        state.lognUser.address.splice(payload.index, 1);
        // window.localStorage.setItem('lognUser', JSON.stringify(state.lognUser));
        this.commit('updateLocalStorage')

    },
    updateImage(state, url) {
        state.lognUser.avatar = url;
        // window.localStorage.setItem('lognUser', JSON.stringify(state.lognUser));
        this.commit('updateLocalStorage')
    },
    assignmentGoods(state, data) {
        state.allGoods.push(...data)
    },
    addGoods(state, data) {
        state.allGoods.push(data)
    },
    delGoods(state, index) {
        state.allGoods.splice(index,1)
    },
    changeGoods(state, payload) {
        state.allGoods.splice(payload.index, 1, payload.data)
    },
    goodsType(state, data) {
        state.goodsType = []
        state.goodsType.push(...data)
    },
    // 收藏操作
    favorites(state, payload) {
        if (payload.addOrSub) {
            state.lognUser.favorites.splice(state.lognUser.favorites.indexOf(payload.id), 1);
        } else {
            state.lognUser.favorites.push(payload.id)
        }
        this.commit('updateLocalStorage');
    },
    // 浏览记录操作
    footFrint(state, payload) {
        let num = state.lognUser.footFrint.indexOf(payload.id);
        if (payload.plus) {
           if (num != -1) {
               state.lognUser.footFrint.splice(num, 1);
           }
           state.lognUser.footFrint.unshift(payload.id);
           if (state.lognUser.footFrint.length > 50) {
               state.lognUser.footFrint.splice(state.lognUser.footFrint.length - 1, 1)
           }
       }else {
            state.lognUser.footFrint.splice(num, 1)
       }
        // this.commit('updateLocalStorage');
    },
    // 获取
    getCart(state, payload) {
       state.cart = payload
    },
    // 删除
    delCartGoods(state, payload) {
        state.cart.splice(payload,1)
    },
    // 更改购物车商品是否进行结算
    changeCartState(state, payload) {
        state.cart[payload].isChoose = !state.cart[payload].isChoose
    },
    updateBusinessUser(state, payload) {
        state.businessUser = payload
    },
    businessSignOut(state) {
        state.businessUser = {}
    },
    updataLogoUrl(state, payload) {
        state.systemMessage.logoUrl = payload
    },
    updataBrand(state, payload) {
        state.systemMessage.brand = payload
    }
}